package com.wty.cmims.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wty.cmims.pojo.Code;
import com.wty.cmims.pojo.Evaluate;
import com.wty.cmims.pojo.ResponseResult;
import com.wty.cmims.service.EvaluateService;
import com.wty.cmims.mapper.EvaluateMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
* @author wty
* @description 针对表【evaluate】的数据库操作Service实现
* @createDate 2025-03-25 13:17:56
*/
@Service
public class EvaluateServiceImpl extends ServiceImpl<EvaluateMapper, Evaluate>
    implements EvaluateService{
    @Autowired
    private EvaluateMapper evaluateMapper;

    @Override
    public ResponseResult<Map<String, Object>> evaluationsFind(Map<String, Object> paramsMap) {
        ResponseResult<Map<String, Object>> responseResult = new ResponseResult<>();
        Integer pageSize = (Integer) paramsMap.get("pageSize");
        paramsMap.put("start", ((Integer) paramsMap.get("currentPage") - 1) * pageSize);
        responseResult.setPageSize(pageSize);
        List<Map<String, Object>> evaluations = evaluateMapper.findEvaluations(paramsMap);
        Integer total = evaluateMapper.findEvaluationsNum(paramsMap);
        if (evaluations != null) {
            responseResult.setCode(Code.SUCCESS);
            responseResult.setMessage("患者评价查询成功");
            responseResult.setDatas(evaluations);
            responseResult.setTotal(total);
            responseResult.setCurrentPage((Integer) paramsMap.get("currentPage"));
        } else {
            responseResult.setCode(Code.ERROR);
            responseResult.setMessage("患者评价查询失败");
        }
        return responseResult;
    }

    @Override
    public ResponseResult<Double> evaluationCompute(Map<String, Object> paramsMap) {
        ResponseResult<Double> responseResult = new ResponseResult<>();
        Double score = evaluateMapper.computeScore(paramsMap);
        if (score != null) {
            responseResult.setCode(Code.SUCCESS);
            responseResult.setMessage("评分计算成功");
            responseResult.setData(score);
        } else {
            responseResult.setCode(Code.ERROR);
            responseResult.setMessage("评分计算失败");
        }
        return responseResult;
    }
}




